package documentation.perspective

import groovy.transform.CompileStatic
import javafx.event.Event
import javafx.geometry.Orientation
import javafx.scene.control.SplitPane
import javafx.scene.layout.BorderPane
import javafx.scene.layout.HBox
import org.jacpfx.api.annotations.lifecycle.OnHide
import org.jacpfx.api.annotations.lifecycle.OnShow
import org.jacpfx.api.annotations.lifecycle.PostConstruct
import org.jacpfx.api.annotations.lifecycle.PreDestroy
import org.jacpfx.api.annotations.perspective.Perspective
import org.jacpfx.api.message.Message
import org.jacpfx.rcp.componentLayout.FXComponentLayout
import org.jacpfx.rcp.componentLayout.PerspectiveLayout
import org.jacpfx.rcp.perspective.FXPerspective

import static documentation.config.IDs.PERSPECTIVE_ONE

/**
 * Created by TK-chenbin on 2015/5/21.
 */
@CompileStatic
@Perspective(id = PERSPECTIVE_ONE,
        name = "PerspectiveOne",
        components = [])
class PerspectiveOne implements FXPerspective {

    @Override
    void handlePerspective(final Message<Event, Object> message,
                           final PerspectiveLayout perspectiveLayout) {

    }

    @OnShow
    void onShow(final FXComponentLayout layout) {
    }

    @OnHide
    void onHide(final FXComponentLayout layout) {
    }

    @PostConstruct
    void onStartPerspective(final PerspectiveLayout perspectiveLayout,
                            final FXComponentLayout layout,
                            final ResourceBundle resourceBundle) {
        def rootPane = new BorderPane()

        def mainLayout = new SplitPane()
        mainLayout.orientation = Orientation.VERTICAL
        mainLayout.setDividerPosition(0, 0.55f)
        rootPane.center = mainLayout

        def contentTop = new HBox()
        def contentBottom = new HBox()

        mainLayout.items.addAll(contentTop, contentBottom)

        perspectiveLayout.registerRootComponent(rootPane)
    }

    @PreDestroy
    void onTearDownPerspective(final FXComponentLayout layout) {
    }
}
